<?php
/**
 * 成员管理控制器
 */

class ManageAction extends BaseAction {
    public function __construct() {
        parent::__construct();

        $this->breadcrumbsPush('管理', U('Manage/index'));
        $this->subnavs = array(
            array(
                'name' => '管理',
                'url' => U('Manage/index'),
                'action' => 'index',
                'icon' => 'wrench',
            ),
            array(
                'name' => '成员',
                'url' => U('Manage/session'),
                'action' => 'data, member, members, sessions, departments',
                'icon' => 'group',
            ),
        );
    }

    public function session() {
        $this->crud('Session');
        $this->breadcrumbsPush('成员', '');
        $this->list = D('Session')->select();
        $this->child = 'department';
        $this->display('Common/crud');
    }

    public function department() {
        $this->crud('Department');
        $this->child = 'post';
        $this->parent = 'session';
        $this->parent_id = $this->_get('session');
        $session = D('Session')
            ->where(array('id' => $this->parent_id))
            ->relation(true)
            ->find();
        $this->list = $session['departments'];
        $this->breadcrumbsPush('成员', U('Manage/session'));
        $this->breadcrumbsPush($session['name'], '');
        $this->display('Common/crud');
    }

    public function post() {
        $this->crud('Post');
        $this->child = 'member';
        $this->parent = 'department';
        $this->parent_id = $this->_get('department');
        $department = D('Department')
            ->where(array('id' => $this->parent_id))
            ->relation(true)
            ->find();
        $this->list = $department['posts'];
        $this->breadcrumbsPush('成员', U('Manage/session'));
        $this->breadcrumbsPush(
            $department['session']['name'],
            U('Manage/department', array(
                'session' => $department['session']['id'])));
        $this->breadcrumbsPush($department['name'], '');
        $this->display('Common/crud');
    }
}
